package org.dormi.learn.product.port.web.material;

import org.dormi.learn.product.application.material.MaterialCreateCmd;
import org.dormi.learn.product.application.material.MaterialCreateInDTO;
import org.dormi.learn.product.application.material.MaterialDTO;
import org.dormi.learn.product.application.material.MaterialQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * add description here
 *
 * @author : dormi330
 * @version : 1.0
 */
@RestController
public class MaterialController {

    @Autowired private MaterialCreateCmd materialCreateCmd;

    @Autowired private MaterialQuery materialQuery;

    @PostMapping("/material")
    public MaterialDTO createMaterial(@RequestBody MaterialCreateInDTO inDTO) {
        MaterialDTO outDto = materialCreateCmd.createMaterial(inDTO);
        return outDto;
    }

    @GetMapping("/material/{id}")
    public MaterialDTO getOne(@PathVariable("id") Long id) {
        MaterialDTO outDto = materialQuery.findOne(id);
        return outDto;
    }
}
